home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / net_bm.arc / MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-05  |  17.5 KB  |  784 lines

  1. /*
  2.  *    Simple mail user interface for KA9Q IP/TCP package.
  3.  *    A.D. Barksdale Garbee II, aka Bdale, N3EUA
  4.  *    Copyright 1986 Bdale Garbee, All Rights Reserved.
  5.  *    Permission granted for non-commercial copying and use, provided
  6.  *    this notice is retained.
  7.  *
  8.  * revision history:
  9.  *
  10.  *  v3.3 870467 D. Trulli nn2z
  11.  *  v3.2 870314 D. Trulli nn2z
  12.  *  v3.1 870117 D. Trulli nn2z
  13.  *    Add multiple arguments mail commands.
  14.  *    Send to multiple users.
  15.  *    Add status commands;
  16.  *  v3.0 871225 D. Trulli nn2z
  17.  *    Heavily restructured program to use a index array of message.
  18.  *    More compatible with UNIX type mail commands.
  19.  *  v2.7 871214 D. Trulli nn2z
  20.  *    Cleaned up header and message parsing to prevent lock up.
  21.  *    Revised command structure.
  22.  *  v2.6 870826 Bdale
  23.  *    integrate PA0GRI's interface/gateway to the WA7MBL PBBS
  24.  *  v2.5 870713 Bdale
  25.  *      integrate additional patches from PA0GRI, minor cleanup
  26.  *  v2.4 870614 - P. Karn
  27.  *      "smart gateway" function moved to smtp client code in net.exe.
  28.  *    User interface for sending mail reworked to resemble Berkeley Mail
  29.  *  v2.3 870524
  30.  *      Extensive addition/revision by Gerard PA0GRI.  Now supports a healthy
  31.  *      set of real commands.  
  32.  *  v2.1,2.2
  33.  *      exact change history lost.
  34.  *  v2.0 c.870115
  35.  *      First version with command parser, only send and quit work.
  36.  *  v1.0
  37.  *      First attempt.  Send messages only.
  38.  */
  39.  
  40. #include <stdio.h>
  41. #include <ctype.h>
  42. #include <string.h>
  43. #include "bm.h"
  44.  
  45. extern char version[];
  46. static char copyright[] = 
  47. "Copyright 1987 Bdale Garbee, permission granted for non-commercial use.";
  48.  
  49. /* comands valid in bm.rc */
  50.  
  51. struct token rccmds[] = {
  52.     "smtp", SMTP,
  53.     "host", HOST,
  54.     "user", USER,
  55.     "edit", EDIT,
  56.     "fullname", NAME,
  57.     "reply", REPLY,
  58.     "maxlet", MAXLET,
  59.     "mbox", MBOX,
  60.     "record", RECORD,
  61.     "screen", SCREEN,
  62.     "folder", FOLDER,
  63.     "mqueue", MQUEUE,
  64.     NULLCHAR, 0
  65. };
  66.  
  67. FILE    *mfile = NULLFILE;
  68. char     *hostname = NULLCHAR;        /* name of this host from rc file */
  69. char    *username = NULLCHAR;        /* name of this user from rc file */
  70. char    *fullname = NULLCHAR;        /* fullname of this user from rc file */
  71. char    *replyto = NULLCHAR;        /* address for reply-to header */
  72. char    *maildir = NULLCHAR;        /* defined mail directory */
  73. char    *mqueue = NULLCHAR;        /* defined mqueue outbound directory */
  74. char    *savebox = NULLCHAR;        /* name of the mbox text file */
  75. char    *record = NULLCHAR;        /* record  outbound mail in this file */
  76. char    *folder = NULLCHAR;        /* directory for saveing read mail */
  77. char    *editor = NULLCHAR;        /* user's favorite text editor */
  78. char    notename[9];            /* name of current notesfile */
  79. char    notefile[SLINELEN];        /* full pathname of mail text file */
  80. char    *mfilename = notefile;    /* pointer to current mbox or mail file -f */
  81. int    current;            /* the current message number */
  82. int    nmsgs;            /* the number of messages in the notesfile */
  83. int    newmsgs;        /* Number of new unread message */
  84. int    change;            /* indicates that the mail file has been
  85.                  * changed in this session */
  86. int    fflag = 0;        /* true if current notesfile is not an mbox */
  87. unsigned maxlet = NLET+1;    /* max number of messages in mailbox */
  88. int    tty;            /* tells if stdin is a tty */
  89. struct let *mbox;        /* pointer to the array of messages */
  90.  
  91.  
  92. char usage[] = "Usage: bm [-u user] [-f file] \n  or bm [-s subject] addr .. addr\n";
  93. char badmsg[] = "Invalid Message number %d\n";
  94. char nomail[] = "No messages\n";
  95. char noaccess[] = "Unable to access %s\n";
  96.  
  97. main(argc,argv)
  98. int argc;
  99. char *argv[];
  100. {
  101.     extern int optind;
  102.     extern char *optarg;
  103.     char *subjectline = NULLCHAR;
  104.     long    tmp;
  105.     int    c;
  106.     int    ret;
  107.  
  108. #if    defined(__TURBOC__) || defined(MICROSOFT)
  109.     (void) fclose(stdaux);
  110.     (void) fclose(stdprn);
  111. #endif
  112.  
  113.     loadconfig();
  114.  
  115.     if (isatty(fileno(stdin))) {
  116.         /* announce ourselves */
  117.         screen_clear();
  118.         printf(" %s\n%s\n\n",version,copyright);
  119.         tty = 1;
  120.     } else
  121.         tty = 0;
  122.  
  123.     current = 1;
  124.     nmsgs = 0;
  125.  
  126.     /* check for important directories */
  127.     if(access(maildir,0)){
  128.         printf(noaccess,maildir);
  129.         exit(1);
  130.     }
  131.     if(access(mqueue,0)){
  132.         printf(noaccess,mqueue);
  133.         exit(1);
  134.     }
  135.     strncpy(notename,username,8);
  136.     notename[8] = '\0';
  137.  
  138.     while ((c = getopt(argc,argv,"u:f:s:")) != -1) {
  139.         switch(c) {
  140.         case 'f':
  141.             fflag++;
  142.             mfilename = optarg;
  143.             break;
  144.         case 's':
  145.             subjectline = optarg;
  146.             break;
  147.         case 'u':
  148.             strncpy(notename,optarg,8);
  149.             notename[8] = '\0';
  150.             break;
  151.         case '?':
  152.             printf(usage);
  153.             exit(1);
  154.         }
  155.     }
  156.  
  157.     /* set any signal handlers to catch break */
  158.     setsignals();
  159.  
  160.     if(optind < argc){
  161.         dosmtpsend(NULLFILE,&argv[optind],argc-optind,subjectline);
  162.         (void) exit(0);
  163.     }
  164.  
  165.     tmp = (long)maxlet * (long)sizeof(struct let);
  166. #ifdef    MSDOS
  167.     /*
  168.     * Since we are in the dos small model make sure that we
  169.     * don't overflow a unsigned short on the number bytes
  170.     * need for mallloc. If not checked malloc will
  171.     * succeed and we will be trashing ourself in no time.
  172.     */
  173.     if ((tmp & 0xffff0000) ||
  174.         (mbox=(struct let *)malloc((unsigned short)tmp)) == (struct let *)NULL){
  175. #else
  176.     if ((mbox=(struct let *)malloc((unsigned)tmp)) == (struct let *)NULL){
  177. #endif
  178.         fprintf(stderr,
  179.         "Can't allocate memory table for %d messages\n",
  180.             maxlet);
  181.         (void) exit(1);
  182.     }
  183.  
  184.     sprintf(notefile,"%s/%s.txt",maildir,notename);
  185.     if (!fflag && lockit())
  186.         exit(1);
  187.     ret = initnotes();
  188.     if (!fflag)
  189.         rmlock(maildir,notename);
  190.     if (ret != 0)
  191.         exit(1);
  192.     listnotes();
  193.     
  194.     getcommand();
  195.     return 0;
  196. }
  197.  
  198. loadconfig()
  199. {
  200.     FILE    *rcfp;    /* handle for the configuration file */
  201.     char    rcline[LINELEN]; /* buffer for config file reading */
  202.     register char *s,*p;
  203.     int line = 0;
  204.     char runcom[LINELEN];
  205.     char *getenv();
  206.  
  207. #ifdef UNIX
  208.     /* Try $HOME/RUNCOM */
  209.     if ((p = getenv("HOME")) != NULLCHAR)
  210.         sprintf(runcom, "%s/%s", p, RUNCOM);
  211. #else
  212.     /* check for BMRC in the ENV */
  213.     if ((p = getenv("BMRC")) != NULLCHAR)
  214.         strcpy(runcom,p);
  215. #endif
  216.     else
  217.         strcpy(runcom,RUNCOM);
  218.  
  219.     if ((rcfp = fopen(runcom,"r")) == NULLFILE) {    /* open config file */
  220.         printf("Cannot open '%s', check your installation\n",runcom);
  221.         (void) exit(1);
  222.     }
  223.     while (!feof(rcfp)) {
  224.         if (fgets(rcline,LINELEN,rcfp) == NULLCHAR)
  225.             break;
  226.         line++;
  227.         rip(rcline);
  228.         if (*rcline == '\0' || *rcline == ';'|| *rcline == '#')
  229.             continue;
  230.         /* find the argument to the command */
  231.  
  232.         s = rcline;
  233.         /* skip the white space */
  234.         while(*s == ' ' || *s == '\t')
  235.                 s++;
  236.         p = s;
  237.         /* skip the command */
  238.         while(*p && *p != ' ' && *p != '\t')
  239.                 p++;
  240.         /* skip the white space */
  241.         while(*p == ' ' || *p == '\t')
  242.                 p++;
  243.         if (*s == '\0')
  244.             continue;
  245.  
  246.         switch (rc_line_type(s)) {
  247.         case HOST:
  248.             hostname = savestr(p);
  249.             break;
  250.         case USER:
  251.             username = savestr(p);
  252.             break;
  253.         case REPLY:
  254.             replyto = savestr(p);
  255.             break;
  256.         case EDIT:
  257.             editor = savestr(p);
  258.             break;
  259.         case SMTP:
  260.             maildir = savestr(p);
  261.             break;
  262.         case NAME:
  263.             fullname = savestr(p);
  264.             break;
  265.         case MAXLET:
  266.             maxlet = atoi(p)+1;
  267.             break;
  268.         case MBOX:
  269.             savebox = savestr(p);
  270.             break;
  271.         case RECORD:
  272.             record = savestr(p);
  273.             break;
  274.         case SCREEN:
  275. #if    defined(__TURBOC__)
  276.             setvideo(p);
  277. #endif
  278.             break;
  279.         case FOLDER:
  280.             folder = savestr(p);
  281.             break;
  282.         case MQUEUE:
  283.             mqueue = savestr(p);
  284.             break;
  285.         default:
  286.             fprintf(stderr,
  287.             "%s: line %d Invalid command: '%s'\n",
  288.             runcom,line,rcline);
  289.             exit(1);
  290.         }
  291.     }
  292.     (void) fclose(rcfp);
  293.     if(maildir == NULLCHAR)
  294.         maildir = mailspool;
  295.     if(mqueue == NULLCHAR)
  296.         mqueue = mailqdir;
  297.     if(savebox == NULLCHAR)
  298.         savebox = "mbox";
  299.     if(hostname == NULLCHAR) {
  300.         fprintf(stderr,"%s: hostname not set\n",runcom);
  301.         exit(1);
  302.     }
  303.     if(username == NULLCHAR) {
  304.         fprintf(stderr,"%s: username not set\n",runcom);
  305.         exit(1);
  306.     }
  307. }
  308.  
  309. /* return the line_type from a line of the configuration file */
  310. rc_line_type(s)
  311. register char *s;
  312. {
  313.     register struct token *tp;
  314.     for (tp = rccmds; tp->str != NULLCHAR; tp++) {
  315.         if (strncmp(tp->str,s,strlen(tp->str)) == 0)
  316.             return tp->type;
  317.     }
  318.     return (NONE);
  319. }
  320.  
  321. /* replace terminating end of line marker(s) with null */
  322. rip(s)
  323. register char *s;
  324. {
  325.     for (; *s; s++)
  326.         if (*s == '\r' || *s == '\n') {
  327.             *s = '\0';
  328.             break;
  329.         }
  330. }
  331.  
  332. /* copy a string return a pointer to it */
  333. char *
  334. savestr(s)
  335. char *s;
  336. {
  337.     register  char *p;
  338.     p = malloc(strlen(s)+1);
  339.     if (p == NULLCHAR) 
  340.         printf("No more memory\n");
  341.     else
  342.         strcpy(p,s);
  343.     return p;
  344. }
  345.  
  346. dohelp()
  347. {
  348.     screen_clear();
  349.     printf("\n\n");
  350.     printf(" d [msglist]           delete a message\n");
  351.     printf(" m userlist            mail a message\n");
  352.     printf(" s [msglist] [file]    save message in file (default mbox)\n");
  353.     printf(" w [msglist] file      save message in file no header\n");
  354.     printf(" f [msg]               forward message\n");
  355.     printf(" b [msg]               bounce message (remail)\n");
  356.     printf(" r [msg]               reply to a message\n");
  357.     printf(" u [msglst]            undelete a message\n");
  358.     printf(" p [msglst]            print message on printer (DOS only)\n");
  359.     printf(" .                     display current message\n");
  360.     printf(" h                     display message headers in notefile\n");
  361.     printf(" l                     list unsent messages\n");
  362.     printf(" k                     kill unsent messages\n");
  363.     printf(" n [file]              display or change notesfile\n");
  364.     printf(" #                     where # is the number of message to read\n");
  365.     printf(" x                     quit without changing mail file\n");
  366.     printf(" q                     quit\n");
  367.     printf(" ! cmd                 run dos command\n");
  368.     printf(" $                     sync the notefile\n");
  369.     printf(" ?                     print this help screen\n");
  370. }
  371.  
  372.  
  373. /* save a message list in a file in mailbox format */
  374. savemsg(argc,argv)
  375. int argc;
  376. register char *argv[];
  377. {
  378.     register char *savefile;
  379.     int msgnum;
  380.     int    i;
  381.     FILE *tfile;
  382.     char buf[LINELEN];
  383.  
  384.     if (mfile == NULLFILE){
  385.         printf(nomail);
  386.         return;
  387.     }
  388.     if (argc == 0 || isdigit(*argv[argc - 1])) {
  389.         savefile = savebox;
  390.     } else {
  391.         savefile = argv[argc - 1];
  392.         --argc;
  393.         /* if it is just a file name and not a path name then check
  394.         ** for a folder path defined and use that path to
  395.         ** save the file.
  396.         */
  397.         if (strpbrk(savefile,"/\\") == NULLCHAR && folder != NULLCHAR) {
  398.             sprintf(buf,"%s/%s",folder,savefile);
  399.             savefile = buf;
  400.         }
  401.     }
  402.     if ((tfile = fopen(savefile,"a")) == NULLFILE) {
  403.         perror(savefile);
  404.         return;
  405.     }
  406.     if (argc == 0)
  407.         msgtofile(current, tfile, 0);
  408.     else {
  409.         for (i = 0; i < argc; i++) {
  410.             msgnum = atoi(argv[i]);
  411.             if (msgnum >= 1 && msgnum <= nmsgs)
  412.                 msgtofile(msgnum, tfile, 0);
  413.             else
  414.                 printf(badmsg,msgnum);
  415.         }
  416.     }
  417.         (void) fclose(tfile);
  418.         printf("%s appended\n",savefile);
  419. }
  420.  
  421. #ifdef MSDOS
  422. /* send messages to the print device */
  423. printmsg(argc,argv)
  424. int argc;
  425. char *argv[];
  426. {
  427.     FILE *prn;
  428.     int msgnum;
  429.     int    i;
  430.  
  431.     if (mfile == NULLFILE){
  432.         printf(nomail);
  433.         return;
  434.     }
  435.     if ((prn = fopen("PRN","a")) == NULL) {
  436.         perror("PRN");
  437.         return;
  438.     }
  439.     if (argc == 0)
  440.         msgtofile(current, prn, 0);
  441.     else {
  442.         for (i = 0; i < argc; i++) {
  443.             msgnum = atoi(argv[i]);
  444.             if (msgnum >= 1 && msgnum <= nmsgs)
  445.                 msgtofile(msgnum, prn, 0);
  446.             else
  447.                 printf(badmsg,msgnum);
  448.         }
  449.     }
  450.     fclose(prn);
  451. }
  452. #endif
  453.  
  454. writemsg(argc,argv)
  455. int argc;
  456. char *argv[];
  457. {
  458.     char *writefile;
  459.     int msgnum;
  460.     int    i;
  461.     FILE *tfile;
  462.  
  463.     if (mfile == NULLFILE){
  464.         printf(nomail);
  465.         return;
  466.     }
  467.     if (argc == 0 || isdigit(*argv[argc - 1])) {
  468.         printf("no file specified\n");
  469.         return;
  470.     } else {
  471.         writefile = argv[argc - 1];
  472.         --argc;
  473.     }
  474.     if ((tfile = fopen(writefile,"a")) == NULLFILE) {
  475.         perror(writefile);
  476.         return;
  477.     }
  478.     if (argc == 0)
  479.         msgtofile(current, tfile, 1);
  480.     else {
  481.         for (i = 0; i < argc; i++) {
  482.             msgnum = atoi(argv[i]);
  483.             if (msgnum >= 1 && msgnum <= nmsgs)
  484.                 msgtofile(msgnum, tfile, 1);
  485.             else
  486.                 printf(badmsg,msgnum);
  487.         }
  488.     }
  489.     (void) fclose(tfile);
  490.     printf("%s appended\n",writefile);
  491. }
  492.  
  493. bmexit(x)
  494. int x;
  495. {
  496.     if(!fflag && lockit())
  497.         exit(1);
  498.     (void) closenotes();
  499.     if (!fflag)
  500.         rmlock(maildir,notename);
  501.     exit(x);
  502. }
  503.  
  504. /* this is the main command processing loop */
  505. getcommand()
  506. {
  507.     FILE *tfile, *tmpfile();
  508.     char    command[LINELEN];    /* command line */
  509.     char    *args[MAXARGS];
  510.     int    nargs;
  511.     char    *cp;
  512.     register int    msgnum;
  513.     register int    i;
  514.     int ret;
  515.  
  516.     printf("\nType ? for help.\n");
  517.  
  518.     /* command parsing loop */
  519.     while(1) {
  520.         printf("\"%s\"> ",notename);
  521.         gets(command);
  522.  
  523.         if (feof(stdin))        /* someone hit ^Z! */
  524.             strcpy(command,"q");    /* treat it like 'q' */
  525.             
  526.         if(*command == '!') {
  527.             if (system(&command[1]))
  528.                 perror("system");
  529.             continue;
  530.         }
  531.         if (*command) {
  532.             cp = command;
  533.             while (*cp && *cp != ' ')
  534.                 cp++;
  535.             nargs = parse(cp,args,MAXARGS);
  536.         }
  537.  
  538.         switch (*command) {
  539.         case 'm':        /* send msg */
  540.             if (nargs == 0) {
  541.                 printf("To: ");
  542.                 gets(command);
  543.                 nargs = parse(command,args,MAXARGS);
  544.             }
  545.             dosmtpsend(NULLFILE,args,nargs,NULLCHAR);
  546.             break;
  547.  
  548.         case 's':        /* save current msg to file */
  549.             savemsg(nargs,args);
  550.             break;
  551.  
  552.         case 'w':        /* write current msg to file */
  553.             writemsg(nargs,args);
  554.             break;
  555.  
  556.         case 'x':        /* abort */
  557.             (void) fclose(mfile);
  558.             (void) exit(0);
  559.             /* NOTREACHED */
  560.             break;
  561.  
  562.         case 'p':        /* print message */
  563. #ifdef MSDOS
  564.             printmsg(nargs,args);
  565. #else
  566.             printf("Command not available in this version\n");
  567. #endif
  568.             break;
  569.  
  570.         case 'r':            /* reply */
  571.             if (nargs == 0)
  572.                 msgnum = current;
  573.             else
  574.                 msgnum = atoi(args[0]);
  575.             if (msgnum >= 1 && msgnum <= nmsgs)
  576.                 reply(msgnum);
  577.             else
  578.                 printf(badmsg,msgnum);
  579.             break;
  580.  
  581.         case 'f':
  582.             if(nargs == 0)
  583.                 msgnum = current;
  584.             else 
  585.                 msgnum = atoi(args[0]);
  586.             if (msgnum < 1 || msgnum > nmsgs) {
  587.                 printf(badmsg,msgnum);
  588.                 break;
  589.             }
  590.             if((tfile = tmpfile()) == NULLFILE)
  591.                 printf("\nCannot open temp file\n");
  592.             else {
  593.                 msgtofile(msgnum,tfile,0);
  594.                 fseek(tfile,0L,0);
  595.                 printf("To: ");
  596.                 gets(command);
  597.                 nargs = parse(command,args,MAXARGS);
  598.                 dosmtpsend(tfile,args,nargs,NULLCHAR);
  599.                 (void) fclose(tfile);
  600.             }
  601.             break;
  602.  
  603.         case 'b':        /* bounce a message */
  604.             if(nargs == 0)
  605.                 msgnum = current;
  606.             else 
  607.                 msgnum = atoi(args[0]);
  608.             if (msgnum < 1 || msgnum > nmsgs) {
  609.                 printf(badmsg,msgnum);
  610.                 break;
  611.             }
  612.             if((tfile = tmpfile()) == NULLFILE)
  613.                 printf("\nCannot open temp file\n");
  614.             else {
  615.                 msgtofile(msgnum,tfile,0);
  616.                 fseek(tfile,0L,0);
  617.                 printf("To: ");
  618.                 gets(command);
  619.                 nargs = parse(command,args,MAXARGS);
  620.                 bouncemsg(tfile,args,nargs);
  621.                 (void) fclose(tfile);
  622.             }
  623.             break;
  624.  
  625.         case 'u':
  626.             if (nargs == 0)
  627.                 mbox[current].status &= ~DELETE;
  628.             else
  629.                 for (i = 0; i < nargs; i++) {
  630.                     msgnum = atoi(args[i]);
  631.                     if( msgnum >= 1 && msgnum <= nmsgs)
  632.                         mbox[msgnum].status &= ~DELETE;
  633.                     else
  634.                         printf(badmsg,msgnum);
  635.                 }
  636.             break;
  637.  
  638.         case 'l':        /* display unsent messages */
  639.             listqueue();
  640.             break;
  641.         case 'k':
  642.             if (nargs == 0)
  643.                 printf("No job id specified\n");
  644.             else
  645.                 for (i = 0; i < nargs; i++) 
  646.                     killjob(args[i]);
  647.             break;
  648.  
  649.         case 'n':     /* display or change notefiles */
  650.             mboxnames(nargs,args);
  651.             break;
  652.         case 'q':        /* quit */
  653.             if (isnewmail()) {
  654.                 printf("New mail has arrived\n");
  655.                 reinit();
  656.             } else
  657.                 bmexit(0);
  658.             /* NOTREACHED */
  659.             break;
  660.         case '$':
  661.             reinit();
  662.             break;
  663.  
  664.         case 'd':        /* delete a message */
  665.             if (nargs == 0)
  666.                 delmsg(current);
  667.             else
  668.                 for ( i = 0; i < nargs; i++) {
  669.                     msgnum = atoi(args[i]);
  670.                     if( msgnum >= 1 && msgnum <= nmsgs)
  671.                         delmsg(msgnum);
  672.                     else
  673.                         printf(badmsg,msgnum);
  674.                 }
  675.             break;
  676.  
  677.         case 'h':        /* list message headers in notesfile */
  678.  
  679.             listnotes();
  680.             break;
  681.  
  682.         case '\0':    /* a blank line prints next message */
  683.             printnext();
  684.             break;
  685.  
  686.         case '?':        /* help */
  687.             dohelp();
  688.             break;
  689.  
  690.         case  '.':
  691.             displaymsg(current);
  692.             break;
  693.         default:
  694.             if (!isdigit(*command))
  695.                 printf("Invalid command - ? for help\n");
  696.             else {
  697.                 msgnum = atoi(command);
  698.                 if (msgnum < 0 || msgnum > nmsgs)
  699.                     printf(badmsg,msgnum);
  700.                 else {
  701.                     current = msgnum;
  702.                     displaymsg(current);
  703.                 }
  704.             }
  705.             break;
  706.         }
  707.     }
  708. }
  709.  
  710. /* list or change mbox */
  711. mboxnames(argc,argv)
  712. int argc;
  713. char *argv[];
  714. {
  715.     register char *cp;
  716.     int ret;
  717.     char    line[80];
  718.     char    buf[LINELEN];
  719.  
  720.     if(argc != 0) {
  721.         if(!fflag && lockit())
  722.             return;
  723.         ret = closenotes();
  724.         if (!fflag)
  725.             rmlock(maildir,notename);
  726.             if (ret != 0)
  727.                 exit(1);
  728.             if (strpbrk(argv[0],"/\\") != NULLCHAR) {
  729.                 fflag = 1;
  730.                 mfilename = argv[0];
  731.             } else {
  732.                 fflag = 0;
  733.                 mfilename = notefile;
  734.                 strncpy(notename,argv[0],8);
  735.                 notename[8] = '\0';
  736.                 sprintf(notefile,"%s/%s.txt",maildir,notename);
  737.             }
  738.             if (!fflag && lockit()) {
  739.                 mfile = NULLFILE;
  740.                 printf("Mail file is busy\n");
  741.                 return;
  742.             }
  743.             ret = initnotes();
  744.             if (!fflag)
  745.                 rmlock(maildir,notename);
  746.             if (ret != 0)
  747.                 exit(1);
  748.             listnotes();
  749.  
  750.         } else {  /* he wants to see what notefiles there are */
  751.             sprintf(buf,"%s/*.txt",maildir,notename);
  752.             filedir(buf,0,line);
  753.             while(line[0] != '\0') {
  754.                 cp = strchr(line,'.');
  755.                 *cp = '\0';
  756.                 printf("notesfile -> %s\n",line);
  757.                 filedir(buf,1,line);
  758.             }
  759.         }
  760. }
  761.  
  762. reinit()
  763. {
  764.     int ret;
  765.     if (!fflag && lockit())
  766.         return;
  767.     ret = closenotes();
  768.     if (!fflag)
  769.         rmlock(maildir,notename);
  770.     if (ret != 0)
  771.         exit(1);
  772.     if (!fflag && lockit()) {
  773.         mfile = NULLFILE;
  774.         printf("Mail file is busy\n");
  775.         return;
  776.     }
  777.     ret = initnotes();
  778.     if (!fflag)
  779.         rmlock(maildir,notename);
  780.     if (ret != 0)
  781.         exit(1);
  782.     listnotes();
  783. }
  784.